<?php


class Deck {
  var $id;
  var $name;
  var $user;
  
  var $cards = array();
  var $cardsCount = array();
  
  var $countCardByType = array();


  function Deck() {
  }
  
  function size() {
    return count($cards);
  }
  
  
  function calculateStats() {
    $size = $this->size(); 
    for($i = 0 ; $i < $size ; $i++) {
        
    }
  }
  
  
  static function getDeck($deckId) {
    $decks = getDecks("Id=".$deckId);
    return $decks[0];
  }
  
  
  static function getDecks($constraint) {
    $query = "SELECT d.Id, d.Name, u.Id AS UserId, u.Name AS UserName
              FROM Deck AS d 
              JOIN User AS u ON u.Id=d.UserId
              WHERE ".$constraint;
    $result = $mysql_query($query);
    
    $decks = array();
    $index = 0;
    while($row = mysql_fetch_object($result)) {
      $user = new User();
      $user->Id = $row->UserId
      $user->Name = $row->UserName
      
      $deck = new Deck();
      $deck->id = $row->Id;
      $deck->name = $row->Name;
      $deck->user = user;
                
      $deck->cards = Card.getCards($deck->Id); 
      $decks[$index] = $deck;    
    }
    return $decks;    
  }
  
  
  
  

}



?>
